/*
 * Copyright (C) 2016 The Android Open Source Project
 *  Created by  Ant  2016/8/29  18:52
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ant.view.cn.activities;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ant.view.cn.R;
import com.ant.view.cn.base.BaseActivity;

/**
 * Created by baichuan on 2016/8/29.
 */
public class SimCardActivity extends BaseActivity implements View.OnClickListener {
    private TextView mTextView;
    private Button mButton;

    private TelephonyManager tmn;

    @Override
    public int getLaout() {
        tmn = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
        return R.layout.ac_simcard_layout;
    }

    @Override
    public void initView() {
        mTextView = (TextView) findViewById(R.id.ac_simcard_textview01);
        mButton = (Button) findViewById(R.id.ac_simcard_obt001);

    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        mButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ac_simcard_obt001:
                getMessage();
                break;
        }
    }

    public void getMessage() {
        StringBuilder sb = new StringBuilder();


        String subscriberId = tmn.getSubscriberId();
        int simState = tmn.getSimState();

        /**
         * 返回移动终端
         *
         * SIM_STATE_ABSENT SIM卡未找到
         * SIM_STATE_NETWORK_LOCKED SIM卡网络被锁定，需要Network PIN解锁
         * SIM_STATE_PIN_REQUIRED SIM卡PIN被锁定，需要User PIN解锁
         * SIM_STATE_PUK_REQUIRED SIM卡PUK被锁定，需要User PUK解锁
         * SIM_STATE_READY SIM卡可用
         * SIM_STATE_UNKNOWN SIM卡未知
         */
        tmn.getSimState();
        sb.append(" 用户id=" + subscriberId);
        sb.append("\n 用户sim卡序号=" + tmn.getSimSerialNumber());
        sb.append("\n 手机号码=" + tmn.getLine1Number());
        sb.append("\n 只能设备唯一编号=" + tmn.getDeviceId());

        mTextView.setText(sb.toString());
    }
}
